home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14551 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  51 lines

  1. Newsgroups: comp.lang.c,comp.unix.programmer
  2. Path: news.uunet.ca!wildcan!sq!msb
  3. From: msb@sq.com (Mark Brader)
  4. Subject: Re: Q: '\n' character
  5. Message-ID: <1996Apr15.185025.564@sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <4kj66f$k0o@ren.cei.net> <4kmhpsINN7ak@keats.ugrad.cs.ubc.ca> <AD97189A966891F2@mcdiala02.it.luc.edu> <4ktn04INNoev@keats.ugrad.cs.ubc.ca>
  8. Date: Mon, 15 Apr 1996 18:50:25 GMT
  9.  
  10. Kazimir Kylheku (c2a192@ugrad.cs.ubc.ca) writes:
  11. > A lot of the standard I/O library ... had to be standardized
  12. > a certain way to reflect existing practice and preserve the
  13. > correctness of existing programs.
  14. >
  15. > Having a return value that is the same as one of the arguments is
  16. > a complete waste of a ``data path'' that could be used to return
  17. > pertinent information.
  18.  
  19. Quite right.
  20.  
  21. > Or better still: how about returning a pointer to the last character
  22. > read!  This would point to a null character if _no_ characters
  23. > were read (thus indicating EOF on the attempt to read the first
  24. > character), or to either a newline or a non-newline if at least one
  25. > character was read.
  26.  
  27. This would certainly have been an improvement.  It would also had made
  28. it rather more convenient to recover semi-gracefully in the case where
  29. there are nulls (meaning null characters, of course) in the input.  With
  30. the actual fgets(), to find all the nulls in the input line, you have to
  31. scan for each instance in the buffer of a null *not* preceded by a newline,
  32. up to and excluding a null that *is* preceded by a newline *or* a null in
  33. the last character of the buffer.  With a pointer to the end of what was
  34. read, you wouldn't have to look at the context of each null.
  35.  
  36. Similarly, it would be more convenient if sprintf() returned a pointer
  37. to the null at the end of what it just wrote, so that the next sprintf()
  38. call could start from there.  In pre-ANSI implementations it sometimes
  39. returned a redundant pointer to the start of its buffer; at least ANSI
  40. standardized on the other behavior that existed, returning the number
  41. of characters written, so the pointer to the null can be computed.
  42.  
  43. Things that might have been.
  44. -- 
  45. Mark Brader   | "A standard is established on sure bases, not capriciously
  46. msb@sq.com    |  but with the surety of something intentional and of a logic
  47. SoftQuad Inc. |  controlled by analysis and experiment.  ... A standard is
  48. Toronto       |  necessary for order in human effort."       -- Le Corbusier
  49.  
  50. My text in this article is in the public domain.
  51.